package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	//一个goroutine需要等待一批goroutine执行完毕以后才继续执行，那么这种多线程等待的问题就可以使用WaitGroup了
	wp := new(sync.WaitGroup)
	wp.Add(10)

	for i := 0; i < 9; i++ {
		fmt.Println("done ", i)
		go func() {
			wp.Done()
		}()
	}

	fmt.Println("wait prepare !")
	time.Sleep(2 * time.Second)
	go func() {
		fmt.Println("last done")
		wp.Done()
	}()
	wp.Wait()
	fmt.Println("wait end !")
}
